#include "Constraint.h"

namespace common {

Constraint::Constraint(int id,int size,GeometricConstraintType type):IdAble(id),size(size),type(type),k(NULL),l(NULL),m(NULL),n(NULL),parameter(NULL){

}

void Constraint::setK(Point* _k){
	k=_k;
}
void Constraint::setL(Point* _l){
	l=_l;
}
void Constraint::setM(Point* _m){
	m=_m;
}
void Constraint::setN(Point* _n){
	n=_n;
}
void Constraint::setParameter(Parameter* param){
	parameter = param;
}
bool Constraint::containsParameter(){
	if(parameter!=NULL){
		return (parameter->getId()>-1)?true:false;
	}
	return false;
}
Point* Constraint::getK(){
	return k;
}
Point* Constraint::getL(){
	return l;
}
Point* Constraint::getM(){
	return m;
}
Point* Constraint::getN(){
	return n;
}
Parameter* Constraint::getParameter(){
	return parameter;
}
void Constraint::setType(GeometricConstraintType typ){
	type =typ;
}

bool Constraint::containsPoint(Point* p){
	if(p==k || p==l || p==m || p==n) return true;
	return false;
}
GeometricConstraintType Constraint::getType(void) const{
	return type;
}
int Constraint::getSize() const{
	return size;
}

ublasVector Constraint::getValue() throw(MyException){
	throw MyException("E-RROR: Metoda nie zaimplementowana");
}
ublasMatrix Constraint::getJacobianOnPoint(Point* p) throw(MyException){
	throw MyException("E-RROR: Metoda nie zaimplementowana");
}

ublasVector Constraint::getNorm() throw(MyException){
	throw MyException("E-RROR: Metoda nie zaimplementowana");
}
ublasMatrix Constraint::getHessian(Point* s, Point* r) throw(MyException){
	throw MyException("E-RROR: Metoda nie zaimplementowana");
}
bool Constraint::isHessian() const{
	return false;
}

std::set<Point*> Constraint::getAssociatedPoint(){
	std::set<Point*> points;
	if(k!=NULL) points.insert(k);
	if(l!=NULL) points.insert(l);
	if(n!=NULL) points.insert(m);
	if(m!=NULL) points.insert(n);
	return points;
}
std::string Constraint::getTypeToString(){
	return GeometricConstraintTypeNames[getType()];
}
std::string Constraint::toString(void){
	std::stringstream o;
	o << "Constraint-" << GeometricConstraintTypeNames[getType()] << " "<< id <<"- [" ;
	if(getK()!=NULL) o <<" p" << getK()->getId() << "-("<< getK()->getX() <<"," <<  getK()->getY() << ")"<< " ,";
	if(getL()!=NULL) o <<" p" << getL()->getId() << "-("<< getL()->getX() <<"," <<  getL()->getY() << ")"<< " ,";
	if(getM()!=NULL) o <<" p" << getM()->getId() << "-("<< getM()->getX() <<"," <<  getM()->getY() << ")"<< " ,";
	if(getN()!=NULL) o <<" p" << getN()->getId() << "-("<< getN()->getX() <<"," <<  getN()->getY() << ")"<< "";
	o << "]";
	if(getParameter()!=NULL) o << " "<< parameter->toString();
	return o.str();
}

Constraint::~Constraint() {

}

}
